package com.java.controller.api;


import com.java.hfb.RequestHelper;
import com.java.pojo.vo.BorrowerVo;
import com.java.result.Result;
import com.java.service.BorrowerService;
import com.java.utils.JwtUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 借款人 前端控制器
 * </p>
 *
 * @author Helen
 * @since 2021-07-08
 */
@Api("账户信息")
@RestController
@RequestMapping("/api/core/borrower")
public class BorrowerController {

    @Resource
    private BorrowerService borrowerService;

    @ApiOperation("保存用户绑定的账户信息")
    @PostMapping("/auth/save")
    public Result save(@RequestBody BorrowerVo borrowerVo , HttpServletRequest request){
        //获取用户id
        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
        borrowerService.saveBorrowerByUserId(borrowerVo,userId);
        return Result.ok();
    }

    @ApiOperation("获取借款人的认证状态")
    @GetMapping("/auth/getBorrowerStatus")
    public Result getBorrowerStatus(HttpServletRequest request){
        String token = request.getHeader("token");
        Long userId = JwtUtils.getUserId(token);
        Integer status = borrowerService.getStatus(userId);
        return Result.ok(status);
    }
}

